/**
 * 追号记录部分前端代码
 */

// 获取页面数据
var rightData = '';
var lott_id = $('#lottery_id').val();
if(!lott_id) console.log('未获取到彩种信息');
$.ajax({  
	type:'post',    
    url: betPageCommonUrl,  
    data:'operation=bet_page_common&lott_id=' + lott_id,  
    cache:false,  
    dataType:'json',  
    async:false,
    success:function(res){  
    	rightData = res;
    }  
})
//console.log(rightData);
if($.isEmptyObject(rightData.lottInfo)) console.log('彩票信息获取失败！');

// 历史投注
$('#id_history_open').html(function (){
	// 根据彩种信息来输出不同格式的历史开奖李新喜
	var str = '';
	switch(rightData.lottInfo.ptid){
		case 'k3':
			str  = '<tbody><tr><th scope="col">期号</th><th scope="col">开奖号</th><th scope="col">和值</th><th scope="col">形态</th></tr></tbody><tbody id="id_history_list" style="font-size: 12px;"></tbody>';
			$('#fn_getoPenGame').html(str);
			var he      = 0;
			var xingtai = '';
            $.each(rightData.history, function (i, v){
            	he      = 0;
            	xingtai = '';
            	$.each(v.code.split(','), function (j, k){
            		he += parseInt(k);
            	})
            	if(he > 10) {
            		xingtai = '<em class="da">大</em>';
            	}else{
            		xingtai = '<em class="xiao">小</em>';
            	}
            	if(he%2){
            		xingtai += '<em class="dan">单</em>';
            	}else{
            		xingtai += '<em class="shuang">双</em>';
            	}
            	str  = '	<tr>';
            	str += '		<td class="c_green"><i class="o_qi">' + v.period + '</i></td>';
            	str += '		<td><i class="numbers">' + v.code + '</i></td>';
            	str += '		<td>' + he + '</td>';
            	str += '		<td>' + xingtai + '</td>';
            	str += '	</tr>';
            	$('#id_history_list').append(str);
            })
			break;
		case 'ssc':
			// 这里的内容好像跟十一选五一样的
		case 'syxw':
			str  = '<tbody><tr><th scope="col">期号</th><th scope="col">开奖号</th><th scope="col">开奖时间</th></tr></tbody><tbody id="id_history_list" style="font-size: 12px;"></tbody>';
			$('#fn_getoPenGame').html(str);
            $.each(rightData.history, function (i, v){
            	str  = '	<tr>';
            	str += '		<td class="c_green"><i class="o_qi">' + v.period + '</i></td>';
            	str += '		<td><i class="numbers">' + v.code + '</i></td>';
            	str += '		<td>' + v.date_opentime + '</td>';
            	str += '	</tr>';
            	$('#id_history_list').append(str);
            })
			break;
		default:
			break;
	}
});

// 我的投注
$('#id_my_bet_list').html(function (){
	setMyBetList('0');
});
// 我的投注
$('#id_mybet_list h3').on('click', '', function (){
	if($(this).attr('class') == "") return;
	$('#id_mybet_list h3').attr('class', 'notSelect');
	$(this).removeClass('notSelect');
	setMyBetList($(this).index());
})
$('#id_all_winner_list').html(function (){
	var str = '';
	$(this).html('');
	$.each(rightData.allwin, function (i, v){
		str  = '<li>';
		str += '	<img src="' + v.head_pic + '"/>';
		if($.isEmptyObject(v.nickname)){
			str += '	<p>' + v.username + '&nbsp;' + v.lott_title + '<br/>';
		}else{
			str += '	<p>' + v.nickname + '&nbsp;' + v.lott_title + '<br/>';
		}
		str += '		喜中<span>¥' + v.prize + '</span>';
		str += '	</p>';
		str += '</li>';
		$('#id_all_winner_list').append(str);
	})
});
$('#id_upday_win_list').html(function (){
	var str = '';
	$(this).html('');
	$(this).append('<tr><th colspan="2">昨日累计盈利排行榜</th></tr>');
	$.each(rightData.updaywin, function (i, v){
		str  = '<tr>';
		str += '	<td>';
		str += '		<img src="' + v.head_pic + '"/>';
		str += '		<p>';
		str += '		账号昵称：' + v.username + '<br/>';
		str += '		昨日盈利：<i>' + v.winner_amount + '</i>';
		str += '		</p>';
		str += '	</td>';
		str += '	<td><ins>' + (i+1) + '</ins></td>';
		str += '</tr>';
		$('#id_upday_win_list').append(str);
	})
});

/**
 * 填充我的投注， 默认普通投注，
 */
function setMyBetList(type=''){
	type       = type ? type : '0';
	var str    = '';
	var winner = '';
	$('#id_my_bet_list').html('');
	$('#id_my_bet_list').html('<tr><th>期号</th><th>投注金额</th><th>奖金<th></tr>');
	$.each(rightData.mybet, function (i, v){
		if(v.chase != type) return true;
		str     = '';
		v.prize = v.prize ? v.prize : '0.00';
		switch(v.winner){
			case '0':
				winner = '未开奖';
				break;
			case '1':
				winner = '未中奖';
				break;
			case '2':
				winner = parseFloat(v.prize).toFixed(2);
				break;
			default :
				winner = '0.00';
				break;
		}
		str += '<tr>';
		str += '	<td>' + v.period + '</td>';
		str += '	<td>' + v.money + '</td>';
		str += '	<td>' + winner + '</td>';
		str += '</tr>';
		$('#id_my_bet_list').append(str);
	})
}

